from odoo import api, fields, models
from ..primary.rp_customer_coupon import COUPON_TYPE
from ..primary.rp_marketing_coupon_template import DISCOUNT_ELIGIBILITY


class RpshipperOrderCouponLine(models.Model):
    _name = 'rp.shipper.order.coupon.line'
    _description = '订单优惠券明细'

    # 基本信息
    name = fields.Char(string='名称', required=True, copy=False)
    currency_id = fields.Many2one(string='货币单位', comodel_name='res.currency', default=lambda self: self.env.company.currency_id)
    code = fields.Char(string='序列号', required=True, copy=False)
    par_value = fields.Float(string='面值', copy=False)
    discount_value = fields.Float(string='折扣', copy=False)
    rp_shipper_order_id = fields.Many2one(string='关联主表', ondelete='cascade', comodel_name='rp.ship.order', required=True, copy=False)
    rp_customer_coupon_id = fields.Many2one(string='客户优惠券', comodel_name='rp.customer.coupon', required=True, copy=False)
    rp_customer_coupon_code = fields.Char(string='优惠券序列号', copy=False)
    coupon_type = fields.Selection(string='优惠券类型', selection=COUPON_TYPE, copy=False)

    # 优惠信息
    coupon_for = fields.Selection(string='优惠对象', selection=DISCOUNT_ELIGIBILITY, required=True, copy=False)
    rp_coupon_mail_route_id = fields.Many2one(string='单一邮路', comodel_name='rp.shipper.mail.route', copy=False)
    rp_coupon_valued_added_id = fields.Many2one(string='增值服务', comodel_name='rp.shipper.sale.template.value.added.line', copy=False)
